package com.base.commonlib.base;

import android.support.annotation.CallSuper;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

import com.base.commonlib.R;
import com.base.commonlib.base.presenter.BasePresenter;


/**
 * Date：2019/4/11 上午9:52
 * Creator：arvin
 * Des：
 */

public abstract class CBaseBarMvpActivity<H extends BasePresenter> extends CBaseMvpActivity<H> {
    private Toolbar mToolbar;
    private TextView mTitle;
    private ImageView mImg;
    private TextView mTvRight;
    @CallSuper
    @Override
    protected void init() {
        mTitle = findViewById(R.id.title);
        mToolbar = findViewById(R.id.bar);
        mImg = findViewById(R.id.img_right);
        mTvRight = findViewById(R.id.tv_right);
        if (mToolbar!=null) {
            mToolbar.setTitle("");
        }
        setSupportActionBar(mToolbar);
    }

    protected void setBarTitle(String tittle)
    {
        if (tittle.length()>10){
            mTitle.setText(tittle.substring(0,10)+"...");
        }else {
            mTitle.setText(tittle);
        }
    }

    protected void setBarColor(int color)
    {
        if (mToolbar != null){
            mToolbar.setBackgroundColor(color);
        }
    }

    protected void setCustTitleColor(int color)
    {
        if (mTitle != null){
            mTitle.setTextColor(color);
        }
    }

    protected void setRigImg(int mResource, View.OnClickListener v){
        if (mImg != null){
            mImg.setBackgroundResource(mResource);
            mImg.setVisibility(View.VISIBLE);
            mImg.setOnClickListener(v);
        }
    }

    protected void setBackNavigation(int resource)
    {
        if (mToolbar!=null){
            mToolbar.setNavigationIcon(resource);
            mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
        }
    }

    protected void setRigTv(String str, View.OnClickListener v){
        if (mTvRight != null){
            mTvRight.setText(str);
            mTvRight.setVisibility(View.VISIBLE);
            mTvRight.setOnClickListener(v);
        }
    }


    protected void setBackNavigation()
    {
        mToolbar.setNavigationIcon(R.drawable.ic_title_back);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    protected void setBackNavigationTip(View.OnClickListener listener)
    {
        mToolbar.setNavigationIcon(R.drawable.ic_title_back);
        mToolbar.setNavigationOnClickListener(listener);
    }
    protected boolean checkTextView(TextView tv) {


        if (TextUtils.isEmpty(tv.getText().toString().trim())) {
            return false;
        } else {
            return true;
        }
    }

    protected boolean checkEditText(EditText et) {
        if (TextUtils.isEmpty(et.getText().toString().trim())) {
            return false;
        } else {
            return true;
        }
    }


    protected boolean checkSpinner(Spinner sp)
    {
        if(sp.getSelectedItem()!=null)
        {
            return true;
        }else
        {
            return false;
        }
    }
}
